<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">项目名称</td>
        <td>{{ form.dealName }}</td>
        <td class="tit">标的公司名称</td>
        <td>
          {{ form.companyName }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">备注</td>
        <td colspan="3">
          {{ form.remark }}
        </td>
      </tr>
    </table>
    <!-- 附件列表 -->
    <FileView :list.sync="form.fileList" data-type="deal_process" :business-id="form.dealId" :btn-show="!otherBtnHide" />
  </div>
</template>

<script>
    import { saveDealWfGeneral, getDealWfGeneral, getByWfNodeId } from '@/api/deal/form/dealWfGeneral'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                  actTitle: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
                // 遮罩层
                loading: false,
                // 操作按钮默认不展示
                buttonShow: true,
                // 是否隐藏保存按钮
                otherBtnHide: false
            }
        },
        created() {
            this.$bus.$emit('async_done')
        },
        methods: {
            // 初始化数据
            init(data) {
              this.loading = true
                if (data != null && data.id !== undefined) {
                    getDealWfGeneral(data.id).then(response => {
                        this.form = response.data
                      this.loading = false
                    })
                } else {
                  getByWfNodeId(data.wfNodeId).then(response => {
                    this.form = response.data
                    this.form.fileList = data.fileList
                    this.loading = false
                  })
                }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                dealId: undefined,
                companyId: undefined,
                actTitle: undefined,
                remark: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            /** 提交按钮 */
            submitForm: function() {
              return new Promise((resolve, reject) => {
                this.$refs['form'].validate(valid => {
                  // 验证数据
                  if (valid) {
                    // 弹出遮罩层
                    this.loading = true
                    // 保存数据
                    saveDealWfGeneral(this.form).then(response => {
                      if (response.code === 200) {
                        this.msgSuccess(this.$t('保存成功'))
                        this.loading = false
                        resolve(response.data.id)
                      } else {
                        this.msgError(response.msg)
                        this.loading = false
                        reject(response)
                      }
                    }).catch(() => {
                      this.loading = false
                    })
                  } else {
                    reject()
                  }
                })
              })
           }

        }

    }
</script>
